let uid = 0;

export default class Dep {
  constructor () {
    // subscibers  ---> Watcher 实例
    this.subs = []
    this.id = uid++
  }
  // 添加依赖
  depend () {
    // 只需要全局无歧义的target即可
    if (Dep.target) {
      this.addSub(Dep.target)
    }
  }

  // 添加订阅
  addSub (sub) {
    this.subs.push(sub)
  }
  notify () {
    // 被监听的数据有了变化了，开始对所有订阅者更新这个变化
    const subs = this.subs.slice()

    for (let k of subs) {
      console.log('更新依赖！')
      k.update()
    }
  }
}